package org.qpcr.community.project.service;

import lombok.extern.slf4j.Slf4j;
import org.hswebframework.ezorm.rdb.mapping.ReactiveQuery;
import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
import org.hswebframework.web.crud.service.GenericReactiveCrudService;
import org.qpcr.community.project.model.entity.TemperatureControlEntity;
import org.qpcr.community.project.model.entity.TestItemInstanceEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

/**
 * 控温算法接口
 */
@Service
@Slf4j
public class TemperatureControlService extends GenericReactiveCrudService<TemperatureControlEntity, String> {
    @Autowired
    private ReactiveRepository<TestItemInstanceEntity, String> repository;

    public Mono<TemperatureControlEntity> findByItemCode(String itemcode,String id) {
        return Mono.justOrEmpty(itemcode).flatMap((_name) -> {
            return ((ReactiveQuery)this.repository.createQuery().where(TemperatureControlEntity::getCode, _name).not(TemperatureControlEntity::getId,id)).fetchOne();
        });
    }
    public Mono<TemperatureControlEntity> findByItemCode(String itemcode) {
        return Mono.justOrEmpty(itemcode).flatMap((_name) -> {
            return ((ReactiveQuery)this.repository.createQuery().where(TemperatureControlEntity::getCode, _name)).fetchOne();
        });
    }

}
